function R = sllogratio(X1, X2)
%SLLOGRATIO Computes the logarithm of the ratios in a robust way
%
% [ Syntax ]
%   - R = sllogratio(X1, X2)
%
% [ Description ]
%   - R = sllogratio(X1, X2) computes the logarithm of ratios as
%       $ R = log(X1 / X2) $
%     in a robust way.
%
%     The computation follows the rules:
%       - if x1 > 0 and x2 > 0, then r = log(x1/x2);
%       - if x1 == 0 and x2 == 0, then r = 0;
%       - if x1 > 0 and x2 == 0, then r = inf
%       - if x1 == 0 and x2 > 0, then r = -inf;
%
% [ Remarks ]
%   - All values in X1 and X2 should be nonnegative.
%
% [ History ]
%   - Created by Dahua Lin, on Jul 30, 2007
%

%% parse and verify input arguments

assert(isfloat(X1) && isfloat(X2) && isa(X2, class(X1)), ...
    'sltoolbox:sllogratio:invalidarg', ...
    'X1 and X2 should be numeric arrays of the same value types.');

assert(isequal(size(X1), size(X2)), ...
    'sltoolbox:sllogratio:invalidarg', 'X1 and X2 should be of the same size.');

%% main

R = log(X1) - log(X2);
R(isnan(R)) = 0;
